layui.use(['form','jquery','jquery_cookie'], function () {
    var form = layui.form,
        layer = layui.layer,
        $ = layui.jquery,
        $ = layui.jquery_cookie($);

    /**
     * ⽤户密码修改 表单提交
     */
    form.on('submit(saveBtn)',function (data){
        //所有表单元素的值
        console.log(data.field);
        //发送ajax
        $.ajax({
            type:"post",
            url:ctx+"/user/updatePwd",
            data:{
                oldPassword:data.field.old_password,
                newPassword:data.field.new_password,
                repeatPassword:data.field.again_password
            },
            success:function (result){
                //判断是否修改成功
                if(result.code ==200){
                    //修改密码后，清空cookie数据，跳转到登录页面
                    layer.msg("用户修改密码成功，系统将在3秒后退出..",function (){
                        //清空cookie
                        $.removeCookie("userIdStr",{domain:"localhost",path:"/crm"})
                        $.removeCookie("userName",{domain:"localhost",path:"/crm"})
                        $.removeCookie("trueName",{domain:"localhost",path:"/crm"})

                        window.parent.location.href = ctx+"/index";
                    });
                }else {
                    layer.msg(result.msg,{icon:5});
                }
            }
        })


    });
});